package com.cmy.servlet;

import com.cmy.pojo.User;
import com.cmy.utils.SendMail;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RegisterServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收用户请求,封装成对象
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        String email = req.getParameter("email");

        User user = new User(username,password,email);
        //用户注册成功之后,给用户发送一封邮件
        //使用线程专门发送邮件,防止出现转圈圈,和注册人数过多时出现的问题
        SendMail send = new SendMail(user);
        //启动线程
        send.start();

        //
        req.setAttribute("message","注册成功,我们已经发送了一封带有注册信息的电子邮件,请查收!若网络存在波动,请稍等(●'◡'●)");
        req.getRequestDispatcher("info.jsp").forward(req,resp);

    }
}

    